<?php
/*
 * 工厂方法模式
 * 举例：日历，书籍的编码器
 */
interface appEncoder{
   function encode();
}
class riliEncoder implements appEncoder{
    function encode()
    {
        echo "日历编码";
    }
}
class bookEncoder implements appEncoder{
    function encode()
    {
        echo "图书编码";
    }
}
abstract class manager{
    abstract function getHeader();
    abstract function getEncode();
    abstract function getFoot();
    public function run(){
        $this->getHeader();
        $this->getEncode();
        $this->getFoot();
    }
}
class riliManager extends manager{
    function getHeader()
    {
        echo "rili header";
    }
    function getEncode()
    {
        (new riliEncoder())->encode();
    }

    function getFoot()
    {
        echo "rili foot";
    }
    function run(){
        $this->getHeader();
        $this->getEncode();
        $this->getFoot();
    }
}
class bookManager extends manager{
    function getHeader()
    {
        echo "bookM header";
    }
    function getEncode()
    {
        (new bookEncoder())->encode();
    }

    function getFoot()
    {
        echo "bookM foot";
    }
}
(new riliManager())->run();